﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using eShop.Model;
using eShop.DataAccess;

namespace eShop.Business
{
    public class CMSManager
    {
        public static void Save(CMS cms)
        {
            CMSDAO.Save(cms);
        }

        public static void Update(CMS cms)
        {
            try
            {
                CMS tblCms = CMSDAO.GetTblCMSByCmsId(cms.CMSId);
                tblCms.CMSContent = cms.CMSContent;
                CMSDAO.Save(tblCms);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static void Create(CMS cms)
        {
            try
            {
                cms.CMSId = CMSDAO.CreateNewTblCMS(cms.CMSType.ToString(), cms.CMSType.ToString(), cms.CMSContent, true, false);
            }
            catch (Exception e)
            {
                throw e;
            }

        }
        public static CMS GetCMS(CMSType cmsType)
        {
            try
            {
                CMS cms = new CMS();
                List<CMS> tmpCms = CMSDAO.GetCMSByCmsType(cmsType.ToString());
                if (tmpCms.Count > 0)
                {
                    cms = tmpCms[0];
                }
                return cms;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public static CMS GetCMS(int cmsID)
        {
            try
            {
                CMS cms = new CMS();
                List<CMS> tmpCms = CMSDAO.GetCMSByCmsID(cmsID);
                if (tmpCms.Count > 0)
                {
                    cms = tmpCms[0];
                }
                return cms;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

    }
}
